package com.cbb.springcloud.controller;

import com.cbb.springcloud.common.entity.PaymentEntity;
import com.cbb.springcloud.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * 订单 controller
 *
 * @author chaibb
 * @date 2021-07-13 16:25:36
 */
@RestController
@RequestMapping("/api/consumer/payment")
@Slf4j
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    private static final String URL = "http://localhost:8001";

    /**
     * 新增
     *
     * @author chaibb
     * @date 2021-07-13 19:03:50
     */
    @PostMapping("/create")
    public Result<String> create(@RequestBody PaymentEntity payment) {
        log.info("payment", payment);
        return restTemplate.postForObject(URL + "/api/payment/create", payment, Result.class);
    }

    /**
     * 根据 id 查看详情
     *
     * @author chaibb
     * @date 2021-07-13 19:03:42
     */
    @GetMapping("/get/{id}")
    public Result<PaymentEntity> getPaymentById(@PathVariable Long id) {
        log.info("id", id);
        return restTemplate.getForObject(URL + "/api/payment/getPaymentById/" + id, Result.class);
    }

}
